struct Person{
    name:String,
    addr:String
}

impl Person{
    fn new(name:String,addr:String)->Person{
        return Person{
            name:name,
            addr:addr
        }
    }

    fn print(&self){
        println!("{} lives in {}",self.name,self.addr);
    }

    fn change(&mut self,name:String,addr:String){
        self.name=name;
        self.addr=addr;
    }   
    fn change2<'a>(&mut self, name: &'a str, addr: &'a str) {
        self.name = name.to_string();
        self.addr = addr.to_string();
    }

    fn change3<'a,'b>(&mut self, name: &'a str, addr: &'b str) {
        self.name = name.to_string();
        self.addr = addr.to_string();
    }

    fn change4(&mut self, name: &str, addr: &str) {
        self.name = name.to_string();
        self.addr = addr.to_string();
    }
    
    fn concat(&self,s1:&str,s2:&str)->String{     
        //+运算符会要求或则左边对象的所有权，所以需要Clone
        //
        //return self.name.clone()+","+&self.addr+","+s1+","+s2;
        return self.name.clone()+","+&(self.addr.clone())+","+s1+","+s2;
    }

}

fn main(){
    let mut p1=Person::new("John".to_string(),"New York".to_string());
    p1.print();
    p1.change("Mike".to_string(),"California".to_string());
    p1.print();
    p1.change2("lzf","中国");
    p1.print();
    let nn=p1.concat("lml","地球");
    println!("{}",nn);
    println!("{}",p1.addr);
}